package com.demo0307.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo0307/demo03.do")
public class Demo03Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // maxAge = -1
        Cookie cookie5 = new Cookie("key5", "value5");
        cookie5.setMaxAge(-1);
        response.addCookie(cookie5);
        // maxAge = 0
        Cookie cookie6 = new Cookie("key1", null);
        cookie6.setMaxAge(0);
        response.addCookie(cookie6);
        // maxAge = 15
        Cookie cookie7 = new Cookie("key7", "value7");
        cookie7.setMaxAge(15);
        response.addCookie(cookie7);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
